/**
 * 音乐/音效/人声设置数据管理;MAX_VALUE :0.99;
 */
var MAX_VALUE = 0.99;
class GLSettingDataModel {
    musicOn: boolean = true;     //音乐开
    soundOn: boolean = true;     //音效开
    voiceOn: boolean = true;     //人声开
    music_vol: number = MAX_VALUE;   //音乐;人声和音效音量同时设置;
    sound_vol: number = MAX_VALUE;    //音效的大小
    voice_vol: number = MAX_VALUE;  //人声;

    tempVolume: 0.99;  //临时记录改变前的设置音量;用于语音前的记录;  


    init() {
        var musicOn = cc.vv.GLCusStorage.getItem("setting_musicOn");
        var soundOn = cc.vv.GLCusStorage.getItem("setting_soundOn");
        var voiceOn = cc.vv.GLCusStorage.getItem("setting_voiceOn");

        this.musicOn = musicOn == "false" ? false : true;
        if (cc.sys.browserType == cc.sys.BROWSER_TYPE_WECHAT) {//苹果内核强行停止;
            cc.vv.GLSettingDataModel.setMusicOn(false);
        }

        this.soundOn = soundOn == "false" ? false : true;
        this.voiceOn = voiceOn == "false" ? false : true;

        this.music_vol = cc.vv.GLCusStorage.getItem("music_vol");
        if (!this.music_vol) {
            this.music_vol = MAX_VALUE;
        }
        console.log("music_vol' value is " + this.music_vol);

        this.sound_vol = cc.vv.GLCusStorage.getItem("sound_vol");
        if (!this.sound_vol) {
            this.sound_vol = MAX_VALUE;
        }
        console.log("sound_vol' value is " + this.sound_vol);
        this.voice_vol = cc.vv.GLCusStorage.getItem("voice_vol");
        if (!this.voice_vol) {
            this.voice_vol = MAX_VALUE;
        }
        console.log("voice_vol' value is " + this.voice_vol);

        if (cc.vv.GLAudioTool) {
            this.setVolume(this.music_vol, this.sound_vol, this.voice_vol);
        }
    }
    /** 
     * 设置音量;
     * @param {音乐音量} music_vol 
     * @param {音效音量} sound_vol 
     * @param {人声音量} voice_vol 
     */
    setVolume(music_vol, sound_vol, voice_vol) {
        this.setMusciVolume(music_vol);
        this.setSoundVolume(sound_vol);
        this.setVoiceVolume(voice_vol);
    }
    //设置音乐大小;
    setMusciVolume(music_vol) {
        this.music_vol = music_vol;
        cc.vv.GLCusStorage.setItem("music_vol", this.music_vol);
        //同步
        if (cc.vv.audioUtil) {
            cc.vv.audioUtil.setMusicVolume(this.music_vol);
        }
    }
    //设置音效大小;
    setSoundVolume(sound_vol) {
        this.sound_vol = sound_vol;
        cc.vv.GLCusStorage.setItem("sound_vol", this.sound_vol);
        if (cc.vv.audioUtil) {
            cc.vv.audioUtil.setSoundVolume(this.sound_vol);
        }
    }
    //设置人声大小;  语音？？？？
    setVoiceVolume(voice_vol) {
        this.voice_vol = voice_vol;
        cc.vv.GLCusStorage.setItem("voice_vol", this.voice_vol);
    }
    /**
     * 临时记录当前音量
     */
    setTempVolume(vol) {
        this.tempVolume = vol;
    }
    getTempVolume() {
        return this.tempVolume;
    }
    /**
     * 设置音乐状态;
     */
    setMusicOn(musicOnFlag) {
        this.musicOn = musicOnFlag
        if (!this.musicOn) {
            cc.vv.audioUtil.stopMusic()
        } else {
            // cc.vv.audioUtil.playMusic();
            cc.vv.eventCustom.emit("MusicOn");
        }
        cc.vv.GLCusStorage.setItem("setting_musicOn", this.musicOn)
    }
    /**
     * 返回音乐音量;
     */
    getMusicVolume() {
        console.log("curse music_vol is " + this.music_vol);
        return this.music_vol;
    }
    /**
     * 返回音效音量;
     */
    getSoundVolume() {
        return this.sound_vol;
    }
    /**
     * 设置音效状态;
     */
    setSoundOn(soundOnFlag) {
        this.soundOn = soundOnFlag
        cc.vv.GLCusStorage.setItem("setting_soundOn", this.soundOn)
    }
    /**
     * 设置人声状态;
     */
    setVoiceOn(voiceOnFlag) {
        this.voiceOn = voiceOnFlag
        cc.vv.GLCusStorage.setItem("setting_voiceOn", this.voiceOn)
    }
    /**
     * 返回音效音量;
     */
    getVoiceVoluem() {
        return this.sound_vol;
    }

    isMusicOn() {
        return this.musicOn
    }
    isSoundOn() {
        return this.soundOn
    }
    isVoiceOn() {
        return this.isVoiceOn
    }
}
export let glSettingDataModel: GLSettingDataModel = new GLSettingDataModel();